package cn.neusoft.neusoft_fz.service.impl;

import cn.neusoft.neusoft_fz.mapper.SubstationMapper;
import cn.neusoft.neusoft_fz.service.SubstationService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.example.entity.Substation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class SubstationServiceImpl extends ServiceImpl<SubstationMapper, Substation> implements SubstationService {

    @Autowired
    private RedisTemplate<String, List<Substation>> redisTemplate;

    @Override
    public List<Substation> list_redis() {
        String cacheKey = "substations";
        List<Substation> cachedSubstations = redisTemplate.opsForValue().get(cacheKey);
        if (cachedSubstations != null) {
            return cachedSubstations;
        }

        List<Substation> substations = this.list();
        redisTemplate.opsForValue().set(cacheKey, substations);
        return substations;
    }
}
